package com.nmsl.sn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.sn.domain.SnMedicalHistory;
import com.nmsl.sn.service.ISnMedicalHistoryService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 病历Controller
 * 
 * @author sn
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/sn/history")
public class SnMedicalHistoryController extends BaseController
{
    @Autowired
    private ISnMedicalHistoryService snMedicalHistoryService;

    /**
     * 查询病历列表
     */
    @PreAuthorize("@ss.hasPermi('sn:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(SnMedicalHistory snMedicalHistory)
    {
        startPage();
        List<SnMedicalHistory> list = snMedicalHistoryService.selectSnMedicalHistoryList(snMedicalHistory);
        return getDataTable(list);
    }

    /**
     * 导出病历列表
     */
    @PreAuthorize("@ss.hasPermi('sn:history:export')")
    @Log(title = "病历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SnMedicalHistory snMedicalHistory)
    {
        List<SnMedicalHistory> list = snMedicalHistoryService.selectSnMedicalHistoryList(snMedicalHistory);
        ExcelUtil<SnMedicalHistory> util = new ExcelUtil<SnMedicalHistory>(SnMedicalHistory.class);
        util.exportExcel(response, list, "病历数据");
    }

    /**
     * 获取病历详细信息
     */
    @PreAuthorize("@ss.hasPermi('sn:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(snMedicalHistoryService.selectSnMedicalHistoryById(id));
    }

    /**
     * 新增病历
     */
    @PreAuthorize("@ss.hasPermi('sn:history:add')")
    @Log(title = "病历", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SnMedicalHistory snMedicalHistory)
    {
        return toAjax(snMedicalHistoryService.insertSnMedicalHistory(snMedicalHistory));
    }

    /**
     * 修改病历
     */
    @PreAuthorize("@ss.hasPermi('sn:history:edit')")
    @Log(title = "病历", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SnMedicalHistory snMedicalHistory)
    {
        return toAjax(snMedicalHistoryService.updateSnMedicalHistory(snMedicalHistory));
    }

    /**
     * 删除病历
     */
    @PreAuthorize("@ss.hasPermi('sn:history:remove')")
    @Log(title = "病历", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(snMedicalHistoryService.deleteSnMedicalHistoryByIds(ids));
    }
}
